import time

from selenium.webdriver.common.by import By

from Ui_Auto_Unittest.base.basepage import BasePage
from Ui_Auto_Unittest.pagelocations.goodspay_page_locs import GoodsPayLoc


class GoodspayPage(BasePage):

    # 继承了BasePage的__init__的属性方法
    # def __init__(self,driver1):
    #     # 定义浏览器的属性
    #     self.driver=driver1

    """
    GoodpayPage:支付页面
    """

    def select_goods(self,goodsname):

        # 输入搜索内容
        self.input("支付页面",GoodsPayLoc.selectcontent_loc,goodsname)
        #点击搜索
        self.click("支付页面",GoodsPayLoc.select_loc)
        self.sleep(1)


    #加入购物车
    def gointocart(self):
        # 鼠标移动到商品
        self.move_element("支付页面",GoodsPayLoc.goods_loc)
        #点击购物车
        self.click("支付页面",GoodsPayLoc.addgoodscart_loc)
        time.sleep(1)

    #结算商品
    def paygoods(self):
        #鼠标移动到购物车结算菜单
        self.move_element("支付页面",GoodsPayLoc.mycartmenu_loc)
        #点击结算按钮
        self.click("支付页面",GoodsPayLoc.allprice_loc)
        self.sleep(1)

    def inputpasswd(self,passwd):
        # 核对购物车商品
        self.click("支付页面",GoodsPayLoc.nextsubmit_loc)
        self.sleep(1)
        #输入支付密码
        self.input("支付页面",GoodsPayLoc.paypasswd_loc,passwd)
        #点击使用
        self.click("支付页面",GoodsPayLoc.userpaypasswd_loc)

    def paymoney(self):
        self.click("支付页面",GoodsPayLoc.submit_loc)
        print("完成支付")

    #获取支付的状态的信息
    def paystateMsg(self):
        print("取支付的状态的信息")
        el= self.locator("支付页面",GoodsPayLoc.paystate_loc)
        return el.text

